package cn.xf.common.bean;

import lombok.Data;

/**
 * 
 * 
 * @description: 微服务接口统一返回码
 * @author: 97后互联网架构师-余胜军
 * @contact: QQ644064779、微信yushengjun644 www.mayikt.com
 * @date: 2019年1月3日 下午3:03:17
 * @version V1.0
 * @Copyright 该项目“基于SpringCloud2.x构建微服务电商项目”由每特教育|蚂蚁课堂版权所有，未经过允许的情况下，
 *            私自分享视频和源码属于违法行为。
 */
@Data
public class ResEnv<T> {

   /**
    * 返回码
    */
   private Integer code;
   /**
    * 消息
    */
   private String msg;
   /**
    * 返回
    */
   private T data;

   public ResEnv(Integer code, String msg, T data) {
      super();
      this.code = code;
      this.msg = msg;
      this.data = data;
   }

   public static <T> ResEnv<T> success(T data) {

      return new ResEnv<T>(200, "success", data);
   }

    public static <T> ResEnv<T> success(String msg, T result) {

        return new ResEnv<T>(200, msg, result);
    }

    public static <T> ResEnv<T> success() {

        return new ResEnv<T>(200, "success", null);
    }

    public static <T> ResEnv<T> success(String msg) {

        return new ResEnv<T>(200, msg, null);
    }

    public static <T> ResEnv<T> fail() {

        return new ResEnv<T>(500, "fail", null);
    }

    public static <T> ResEnv<T> fail(String msg) {

        return new ResEnv<T>(500, msg,null);
    }

    public static <T> ResEnv<T> fail(String msg, T data, int code) {

        return new ResEnv<T>(code, msg, data);
    }

    public static <T> ResEnv<T> fail(int code, String msg) {

        return fail(msg, null,  code);
    }
}